#!/usr/bin/env node
const fs = require('fs');
const path = require('path');

const startPath = process.cwd(); // 你可以更改为你想要开始搜索的目录
console.log(startPath)
function removeGitFolders (dir) {
  fs.readdir(dir, (err, files) => {
    if (err) {
      console.error(`Error reading directory ${dir}:`, err);
      return;
    }

    files.forEach(file => {
      const filePath = path.join(dir, file);
      fs.stat(filePath, (err, stats) => {
        if (err) {
          console.error(`Error getting stats of file ${filePath}:`, err);
          return;
        }

        if (stats.isDirectory()) {
          if (file === '.git' && dir !== startPath) {
            console.log(`Removing: ${filePath}`);
            fs.rmdir(filePath, { recursive: true }, err => {
              if (err) {
                console.error(`Error removing directory ${filePath}:`, err);
              }
            });
          } else {
            removeGitFolders(filePath);
          }
        }
      });
    });
  });
}

removeGitFolders(startPath);